Program add_total_short_episode
      character*6 ticker
      character*8 cusp,cusip(174292),fcusip(1300),lcusp
      integer(kind=8):: nshrs,nvalue,jvalue,ivol,numshrs,ntot(174292)
      dimension ndate(174292),nbeg(1300)
!      open(unit=10,file='e:\FIS_duration\short_int_episode.txt')
!      open(unit=11,file='e:\FIS_duration\episode_date_type.txt')
!      open(unit=99,file='e:\FIS_duration\episode_data_type_total.txt')
      open(unit=10,file='e:\FIS_duration\short_int_episode_rep.txt')
      open(unit=11,file='e:\FIS_duration\episode_data_type_rep.txt')
      open(unit=99,file='e:\FIS_duration\episode_data_type_total_rep.txt')
      lcusp='kkkkkkkk'
      nc=0
      do 10 i=1,174291
      read(10,1000)cusip(i),ndate(i),ntot(i)
1000  format(1x,a8,1x,i8,1x,i12)      
      if(cusip(i).eq.lcusp) go to 10
      lcusp=cusip(i)
      nc=nc+1
      fcusip(nc)=cusip(i)
      nbeg(nc)=i
10    continue
      write(6,6000)nc
6000  format(1x,i6)   
      lcusp='xxxxxxxx'
      nn=1
20    read(11,1100,end=900)nep,ntype,jast,jyr,jmn,jdy,cusp,ticker,itickt,numshrs,age,favg,fmax,fmin,fstd,iperm,price,ivol,retrn,ishrout,vwret,util,nshrs      
1100  format(1x,i4,1x,i1,1x,i8,1x,i4,2i2,1x,a8,2x,a6,4x,i9,1x,i14,5(1x,f11.4),1x,i5,1x,f9.2,1x,i10,1x,f10.6,1x,i9,1x,f9.6,1x,f6.2,1x,i13) 
      jdate=jyr*10000+jmn*100+jdy
      if(jdy.gt.10.and.jdy.lt.20) go to 50
      if(jdy.gt.25) go to 50
      write(99,1100)nep,ntype,jast,jyr,jmn,jdy,cusp,ticker,itickt,numshrs,age,favg,fmax,fmin,fstd,iperm,price,ivol,retrn,ishrout,vwret,util,nshrs    
      go to 20
50    continue  
      if(cusp.eq.lcusp) go to 70
      lcusp=cusp
      nn=0
55    nn=nn+1
      if(nn.gt.nc) go to 70
      if(cusp.eq.fcusip(nn)) go to 70
      go to 55
70    continue 
      if(nn.gt.nc) write(99,1100)nep,ntype,jast,jyr,jmn,jdy,cusp,ticker,itickt,numshrs,age,favg,fmax,fmin,fstd,iperm,price,ivol,retrn,ishrout,vwret,util,nshrs
      if(nn.gt.nc) go to 20
      ii=nbeg(nn)-1
75    ii=ii+1
      if(cusip(ii).ne.cusp.or.ii.gt.174291) write(99,1100)nep,ntype,jast,jyr,jmn,jdy,cusp,ticker,itickt,numshrs,age,favg,fmax,fmin,fstd,iperm,price,ivol,retrn,ishrout,vwret,util,nshrs
      if(cusip(ii).ne.cusp.or.ii.gt.174291) go to 20
      if(jdate.ne.ndate(ii)) go to 75
      write(99,9900)nep,ntype,jast,jyr,jmn,jdy,cusp,ticker,itickt,numshrs,age,favg,fmax,fmin,fstd,iperm,price,ivol,retrn,ishrout,vwret,util,nshrs,ntot(ii)
9900  format(1x,i4,1x,i1,1x,i8,1x,i4,2i2,1x,a8,2x,a6,4x,i9,1x,i14,5(1x,f11.4),1x,i5,1x,f9.2,1x,i10,1x,f10.6,1x,i9,1x,f9.6,1x,f6.2,1x,i13,1x,i12) 
      go to 20
900   continue
      stop
end program add_total_short_episode